package com.jzo2o.customer.controller.consumer;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.model.domain.AddressBook;
import com.jzo2o.customer.model.dto.request.AddressBookPageQueryReqDTO;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.service.IAddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @Author mr.luo
 * @Date 01 7月 2025 16:44
 */
@RestController("consumerAddressBookController")
@RequestMapping("/consumer")
@Api(tags = "用户端 - 地址相关接口")
public class AddressBookController {
    @Autowired
    private IAddressBookService addressBookService;

    /**
     * 新增地址
     */
    @PostMapping("/address-book")
    @ApiOperation("新增地址")
    public void add(@RequestBody AddressBookUpsertReqDTO dto) {
        addressBookService.add(dto);
    }


    /**
     * 查询地址
     */
    @GetMapping("/address-book/page")
    @ApiOperation("查询地址")
    public PageResult<AddressBook> queryAddress(AddressBookPageQueryReqDTO dto ) {
       return addressBookService.queryAddress(dto);
    }
    /**
     * 根据id回显地址
     */
    @GetMapping("/address-book/{id}")
    @ApiOperation("根据id回显地址")
    public AddressBook queryById(@PathVariable Long id ) {
        return addressBookService.queryById(id);
    }

    /**
     * 修改地址
     */
    @PutMapping("/address-book/{id}")
    @ApiOperation("修改地址")
    public void update(@PathVariable Long id, @RequestBody AddressBookUpsertReqDTO dto) {
        addressBookService.updateAddress(id,dto);
    }
    /**
     * 批量删除地址
     */
    @DeleteMapping("/address-book/batch")
    @ApiOperation("批量删除地址")
    public void deleteBatch(@RequestBody List<String> ids) {
        addressBookService.deleteBatch(ids);
    }

    /**
     * 设置/取消默认地址
     */
    @PutMapping("/address-book/default")
    @ApiOperation("设置/取消默认地址")
    public void setIsDefault(Long id, Integer flag) {
        addressBookService.setIsDefault(id, flag);
    }

    /**
     * 获取默认地址
     */
    @GetMapping("/address-book/defaultAddress")
    @ApiOperation("获取默认地址")
    public AddressBook getDefaultAddress() {
       return addressBookService.getDefaultAddress();
    }

}
